{% extends "base/base.html" %}

{% block title %}查看异常数据 - 项目合作归属数据管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h2><i class="bi bi-exclamation-triangle"></i> 异常数据详情</h2>
        <p class="text-muted">文件：{{ exception.filename }}</p>
    </div>
</div>

<!-- 异常信息卡片 -->
<div class="card mb-4">
    <div class="card-header">
        <h5 class="mb-0">基本信息</h5>
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col-md-3">
                <strong>文件名：</strong><br>
                {{ exception.filename }}
            </div>
            <div class="col-md-3">
                <strong>处理状态：</strong><br>
                {% if exception.status == '待处理' %}
                    <span class="badge bg-warning">待处理</span>
                {% else %}
                    <span class="badge bg-success">已处理</span>
                {% endif %}
            </div>
            <div class="col-md-3">
                <strong>上传时间：</strong><br>
                {{ exception.upload_time.strftime('%Y-%m-%d %H:%M:%S') if exception.upload_time else '-' }}
            </div>
            <div class="col-md-3">
                <strong>上传人：</strong><br>
                {{ exception.uploader or '-' }}
            </div>
        </div>
        
        {% if exception.processor or exception.process_time %}
        <hr>
        <div class="row">
            <div class="col-md-6">
                <strong>处理人：</strong><br>
                {{ exception.processor or '-' }}
            </div>
            <div class="col-md-6">
                <strong>处理时间：</strong><br>
                {{ exception.process_time.strftime('%Y-%m-%d %H:%M:%S') if exception.process_time else '-' }}
            </div>
        </div>
        {% endif %}
        
        {% if exception.error_reason %}
        <hr>
        <div class="row">
            <div class="col-12">
                <strong>异常原因：</strong><br>
                <div class="alert alert-warning mt-2">
                    {{ exception.error_reason }}
                </div>
            </div>
        </div>
        {% endif %}
    </div>
</div>

<!-- 详细异常数据 -->
<div class="card">
    <div class="card-header">
        <h5 class="mb-0">详细异常数据</h5>
    </div>
    <div class="card-body">
        {% if error_data %}
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th width="60">序号</th>
                            <th>异常详情</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for error in error_data %}
                        <tr>
                            <td>{{ loop.index }}</td>
                            <td>
                                <div class="alert alert-danger mb-0">
                                    <i class="bi bi-exclamation-circle"></i> {{ error }}
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        {% else %}
            <div class="text-center text-muted py-4">
                <i class="bi bi-info-circle" style="font-size: 3rem;"></i>
                <p class="mt-3">暂无详细异常数据</p>
            </div>
        {% endif %}
    </div>
</div>

<!-- 操作按钮 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="d-flex justify-content-between">
            <a href="{{ url_for('negotiation.upload_exceptions') }}" class="btn btn-secondary">
                <i class="bi bi-arrow-left"></i> 返回列表
            </a>
            
            {% if exception.status == '待处理' %}
            <form method="POST" action="{{ url_for('negotiation.mark_exception_processed') }}" style="display: inline;">
                <input type="hidden" name="exception_ids" value="{{ exception.id }}">
                <button type="submit" class="btn btn-success" onclick="return confirm('确定要标记为已处理吗？')">
                    <i class="bi bi-check-circle"></i> 标记为已处理
                </button>
            </form>
            {% endif %}
        </div>
    </div>
</div>

<!-- 处理建议 -->
<div class="card mt-4">
    <div class="card-header">
        <h5 class="mb-0"><i class="bi bi-lightbulb"></i> 处理建议</h5>
    </div>
    <div class="card-body">
        <ul class="list-unstyled mb-0">
            <li><i class="bi bi-check-circle text-success"></i> 检查数据格式是否符合模板要求</li>
            <li><i class="bi bi-check-circle text-success"></i> 确认时间格式为 YYYY/MM/DD HH:MM:SS</li>
            <li><i class="bi bi-check-circle text-success"></i> 验证必填字段是否完整</li>
            <li><i class="bi bi-check-circle text-success"></i> 检查项目负责人姓名是否存在于系统中</li>
            <li><i class="bi bi-check-circle text-success"></i> 确认商谈类别为"线上合作商谈"或"线下合作商谈"</li>
        </ul>
    </div>
</div>
{% endblock %}

